# @Author  : wangyiruo
# @Time    : 2024/12/5 19:39
# @Project：Python70_class

from faker import Faker
from loguru import logger

from data.setting import my_db
from tools.handle_mysql import HandleMysql



#封装
class GenData:
    def gen_unregister_phone(self):
        fk = Faker(locale="zh_CN")
        while True:
            phone_num = fk.phone_number()
            sql = f'select * from tz_user where user_mobile="{phone_num}";'
            result = HandleMysql(**my_db).query_data(sql)
            if result is None:
                logger.info(f"生成的号码是:{phone_num}")
                return phone_num

    def gen_unregister_name(self):
        fk = Faker(locale="zh_CN")
        while True:
            # name = fk.user_name()
            name = fk.pystr(min_chars=4, max_chars=16)
            sql = f'select * from tz_user where nick_name="{name}";'
            result = HandleMysql(**my_db).query_data(sql)

            if result is None:
                logger.info(f"生成的用户名是:{name}")
                return name

if __name__ == '__main__':
    # GenData().gen_unregister_phone()
    GenData().gen_unregister_name()

